import {Resources} from "./Resources.js"

export class ResourceLoader {
  constructor() {
    this.map = new Map(Resources)

    for (let [key, val] of this.map) {
      let img = new Image()
      img.src = val
      this.map.set(key, img)
    }
  }

  onLoaded(cb) {
    let count = 0
    for (let val of this.map.values()) {
      val.onload = () => {
        count++
        if (count >= this.map.size) cb(this.map)
      }
    }
  }

  static create() {
    return new ResourceLoader()
  }
}
